
package logins;

import com.opensymphony.xwork2.ActionContext;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;

public class loginProcess {
    
    private String account;
    private String password;  
    private HashMap<String,Object> res;
    //HttpServletRequest request=ServletActionContext.getRequest(); 
    //Map session=ActionContext.getSession();
    
    
    public loginProcess() {
    }

    public String IndexLogin() throws Exception {
        
        String result;
        Map session=(Map)ActionContext.getContext().get(ActionContext.SESSION);
        
        NWDB.NWDB mydb=new NWDB.NWDB();
        NWDB.IMember im=new NWDB.ImplMember(mydb.getConnection());
        mydb.setIMember(im);
        
        if(mydb.CheckLogin(account, password))
        {
            session.put("User", account) ;
            
            res=mydb.getAccount(account, password);        
            session.put("會員編號", res.get("會員編號"));
            
            result="indexsuccess";
        }
        else 
        {
            session.put("mes", "您的帳號或密碼輸入有誤！") ;
            result="indexfail"; 
        }
        
        return result;
    }
    
     public String logout() throws Exception {
        
        Map session=(Map)ActionContext.getContext().get(ActionContext.SESSION);
        
        session.remove("User");
        session.remove("會員編號");
        session.remove("Cart");
        //session.clear();
        return "success";
    }
    
    public String getAccount() {
        return account;
    }
    public void setAccount(String account) {
        this.account = account;
    }

    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the res
     */
    public HashMap<String,Object> getRes() {
        return res;
    }

    /**
     * @param res the res to set
     */
    public void setRes(HashMap<String,Object> res) {
        this.res = res;
    }
    
   
    
}
